home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 July: Mac OS SDK / Dev.CD Jul 00 SDK2.toast / Development Kits / Hardware / Mac OS USB DDK / Mac OS USB DDK 1.4.1 / Examples / PowerClassQueryDevice / QueryDevice.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-04-25  |  2.0 KB  |  94 lines  |  [TEXT/CWIE]

  1. /*
  2.  *  QueryDevice.c
  3.  *  © 1999 Apple Computer, Inc.
  4.  *
  5.  *  Sample showing the use of the USBPowerShim API
  6.  *  Comments: Tom Clark, tclark@apple.com
  7.  *  
  8.  */
  9.  
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <USB.h>
  13. #include "PowerClass.h"
  14.  
  15. int main(void)
  16. {
  17. OSStatus                status = noErr;
  18. PowerDeviceDescriptor    device;
  19. UInt16                    x = 0;
  20. UInt32                    choice = 0;
  21. UInt32                    ref;
  22. UInt32                    collection;
  23. UInt32                    page;
  24. UInt32                    usage;
  25. SInt32                    value;
  26.     
  27.     device.reference = kNoDeviceRef;        // Prime the search
  28.     do
  29.     {
  30.         status = GetNextPowerDevice (&device);
  31.         if (noErr == status)
  32.         {
  33.             printf ("Device Found.  Reference: 0x%X\n", device.reference);
  34.         }    
  35.     } while (noErr == status);
  36.  
  37.  
  38.         printf ("\nDevice Reference To Query: ");
  39.         scanf ("%x", &ref);
  40.             
  41.     while (1)
  42.     {
  43.     
  44.         printf ("\n[1] Get Usage Data\n");
  45.         printf ("[2] Set Usage Data\n");
  46.         printf ("Choice: ");
  47.         scanf ("%d", &choice);
  48.         
  49.         switch (choice)
  50.         {
  51.             case (1):
  52.                 printf ("\nCollection: ");
  53.                 scanf ("%x", &collection);
  54.                 printf ("Usage Page: ");
  55.                 scanf ("%x", &page);
  56.                 printf ("Usage: ");
  57.                 scanf ("%x", &usage);
  58.                 status = USBPowerGetUsageData (ref, collection, page, usage, &value);    // Ask the shim for the info
  59.                 if (noErr == status)
  60.                     printf ("Value Returned: %d\n", value);
  61.                 else if (status == kUSBPending)    
  62.                 {
  63.                     status = USBPowerGetUsageData (ref, collection, page, usage, &value);    // Ask the shim for the info
  64.                     if (noErr == status)
  65.                         printf ("Value Returned: %d\n", value);
  66.                     else
  67.                         printf ("Error: %d\n", status);
  68.                 }        
  69.                 else
  70.                     printf ("Error: %d\n", status);
  71.                 break;    
  72.             case (2):
  73.                 printf ("\nCollection: ");
  74.                 scanf ("%x", &collection);
  75.                 printf ("Usage Page: ");
  76.                 scanf ("%x", &page);
  77.                 printf ("Usage: ");
  78.                 scanf ("%x", &usage);
  79.                 printf ("Value: ");
  80.                 scanf ("%d", &value);
  81.                 status = USBPowerSetUsageData (ref, collection, page, usage, value);    
  82.                 printf ("Status Returned: %d\n", status);
  83.                 break;    
  84.             default:
  85.                 break;
  86.         
  87.         }
  88.         
  89.     }        
  90.     
  91. return 0;
  92. }
  93.  
  94.